package br.uvv.sao.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import br.uvv.sao.enums.SituOfertaDisciplina;

@Entity
@Table(name = "sao_oferta_disciplina")
public class OfertaDisciplina implements Serializable {

	private static final long serialVersionUID = 647316026068172028L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Version
	private Integer version = 0;

	@Column(name = "semestre", length = 2, nullable = false)
	private String semestre;

	@Column(name = "data", nullable = false)
	private Date ano;

	@Enumerated(EnumType.ORDINAL)
	@Column(name = "situacao")
	private SituOfertaDisciplina situacao;

	// Professor responsável
	@ManyToOne(optional = false, targetEntity = Professor.class, fetch = FetchType.EAGER)
	@JoinColumn(name = "professor_id", nullable = false)
	private Professor professor;

	// Disciplina lecionada responsável
	@ManyToOne(optional = false, targetEntity = Disciplina.class, fetch = FetchType.EAGER)
	@JoinColumn(name = "disciplina_id", nullable = false)
	private Disciplina disciplina;

	@OneToMany(targetEntity = AlunoOferta.class, fetch = FetchType.LAZY, mappedBy = "ofertaDisciplina")
	@Cascade(value=CascadeType.ALL)
	private List<AlunoOferta> alunosMatriculados;
	
	@OneToMany(targetEntity = Prova.class, fetch = FetchType.LAZY, mappedBy = "aplicadaEm")
	private List<Prova> provas;

	public OfertaDisciplina() {
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getSemestre() {
		return semestre;
	}

	public void setSemestre(String semestre) {
		this.semestre = semestre;
	}

	public SituOfertaDisciplina getSituacao() {
		return situacao;
	}

	public void setSituacao(SituOfertaDisciplina situacao) {
		this.situacao = situacao;
	}

	public Professor getProfessor() {
		return professor;
	}

	public void setProfessor(Professor professor) {
		this.professor = professor;
	}

	public Disciplina getDisciplina() {
		return disciplina;
	}

	public void setDisciplina(Disciplina disciplina) {
		this.disciplina = disciplina;
	}

	public List<AlunoOferta> getAlunosMatriculados() {
		return alunosMatriculados;
	}

	public void setAlunosMatriculados(List<AlunoOferta> alunosMatriculados) {
		this.alunosMatriculados = alunosMatriculados;
	}

	public Date getAno() {
		return ano;
	}

	public void setAno(Date ano) {
		this.ano = ano;
	}

	public List<Prova> getProvas() {
		return provas;
	}

	public void setProvas(List<Prova> provas) {
		this.provas = provas;
	}
}
